package com.maxd.respository.money;

import com.maxd.model.MoneyDetails;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;


public interface MoneyDetailsRepository extends Repository<MoneyDetails, Long> {


    @Query(value = "select * from money_details where user_id=:userId",
            countQuery = "select count(*) from money_details where user_id=:userId",
            nativeQuery = true)
    Page<MoneyDetails> selectMoneyDetailsByUserId(Pageable pageable,@Param("userId") Long userId);

    @Query(value = "select * from money_details where merchant_id=:merchantId " +
            "and if(:classify!=0,classify=:classify,1=1) order by create_time desc ",
            countQuery = "select count(*) from money_details where merchant_id=:merchantId " +
                    "and if(:classify!=0,classify=:classify,1=1) ",
            nativeQuery = true)
    Page<MoneyDetails> selectMoneyDetailsByMerchantId(Pageable pageable,@Param("merchantId") Long merchantId,@Param("classify") Integer classify);

}